package com.yc.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zwei
 * @create 2024-08-22 15:22
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override       //插入时自动填充
    public void insertFill(MetaObject metaObject) {
        strictFillStrategy(metaObject,"optime",()->{    //使用lambda表达式对于数据库中该列进行自动填充
            Date date = new Date();
            DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return df.format(date);
        });
    }

    @Override       //更新时自动填充
    public void updateFill(MetaObject metaObject) {

    }
}
